package com.itheima05;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Car> s1 = new TreeSet<>(new Comparator<Car>() {
            @Override
            public int compare(Car o1, Car o2) {
                //比价格
                int result = Double.compare(o2.getPrice(), o1.getPrice());
                //比车龄
                result = (result == 0) ? o2.getAge() - o1.getAge() : result;
                //比品牌
                result = (result == 0) ? o2.getBrand().compareTo(o1.getBrand()) : result;
                return result;
            }
        });
        s1.add(new Car("mashaladi", 2, 10.2));
        s1.add(new Car("labojini", 1, 10.3));
        s1.add(new Car("falali", 3, 10.1));
        s1.add(new Car("naosilaisi", 2, 12.2));
        s1.add(new Car("wulinghongguang", 4, 11.2));
        s1.add(new Car("wulinghongguang", 4, 11.2));
        s1.forEach(c -> System.out.println(c));
    }
}
